package mutsumimod.cards.derivative;

import basemod.AutoAdd;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import mutsumimod.cards.BaseCard;
import mutsumimod.cards.copy.UnhealthyUika;
import mutsumimod.character.Mutsumi;
import mutsumimod.util.CardStats;

@AutoAdd.Ignore
public class UnhealthyMutsumi extends BaseCard  {
    public static final String ID = makeID(UnhealthyMutsumi.class.getSimpleName());
    public static final CardStats info = new CardStats(
            Mutsumi.Meta.CARD_COLOR,
            CardType.ATTACK,
            CardRarity.UNCOMMON,
            CardTarget.ENEMY,
            0
    );

    public UnhealthyMutsumi() {
        super(ID, info);
        setAttr(3,0,2);
        setAttrUpg(1,0,0);
    }

    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {
        damageMonster(m);
    }

    public int countCards() {
        int count = 0;
        for(AbstractCard c : AbstractDungeon.player.hand.group) {
            if (isUnhealthy(c)) {
                ++count;
            }
        }
        for(AbstractCard c : AbstractDungeon.player.drawPile.group) {
            if (isUnhealthy(c)) {
                ++count;
            }
        }
        for(AbstractCard c : AbstractDungeon.player.discardPile.group) {
            if (isUnhealthy(c)) {
                ++count;
            }
        }
        return count;
    }

    public boolean isUnhealthy(AbstractCard c) {
        return c instanceof UnhealthyMutsumi||c instanceof UnhealthyUika;
    }

    public void calculateCardDamage(AbstractMonster mo) {
        int realBaseDamage = this.baseDamage;
        this.baseDamage += this.magicNumber * countCards();
        super.calculateCardDamage(mo);
        this.baseDamage = realBaseDamage;
        this.isDamageModified = this.damage != this.baseDamage;
    }

    public void applyPowers() {
        int realBaseDamage = this.baseDamage;
        this.baseDamage += this.magicNumber * countCards();
        super.applyPowers();
        this.baseDamage = realBaseDamage;
        this.isDamageModified = this.damage != this.baseDamage;
    }

    @Override
    public AbstractCard makeCopy() {
        return new UnhealthyMutsumi();
    }
}